package com.zcp.todayheadline.fragment;


import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.lianghanzhen.LazyFragmentPagerAdapter;
import com.github.lianghanzhen.LazyViewPager;
import com.headline.pagerslidingtabstrip.PagerSlidingTabStrip;
import com.zcp.todayheadline.R;


public class VideoFragment extends Fragment {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    PagerSlidingTabStrip ps_video;
    LazyViewPager lazy_video;


    public VideoFragment() {

    }


    public static VideoFragment newInstance(String param1, String param2) {
        VideoFragment fragment = new VideoFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_video, container, false);

        //初始化
        initView(view);
        return view;
    }

    //初始化
    public void initView(View view) {
        ps_video = (PagerSlidingTabStrip) view.findViewById(R.id.ps_video);
        lazy_video = (LazyViewPager) view.findViewById(R.id.lazy_video);

        //设置适配器
        lazy_video.setAdapter(new VideoFragmentAdapter(getActivity().getSupportFragmentManager()));

        //实现联动效果
        ps_video.setViewPager(lazy_video);

        //设置滑动颜色
        ps_video.setTextColor(Color.RED);
        ps_video.setTextSize(48);
        ps_video.setIndicatorColor(Color.BLUE);
        ps_video.setIndicatorHeight(2);
    }

    //设置适配器
    class VideoFragmentAdapter extends LazyFragmentPagerAdapter {
        String[] titles = new String[]{"热点", "娱乐", "搞笑", "精品"};

        public VideoFragmentAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        protected Fragment getItem(ViewGroup container, int position) {
            return VideoInfoFragment.newInstance(titles[position], position + "");
        }

        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }
    }

}
